home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / dix / RCS / glyphcurs.c,v < prev    next >
Encoding:
Text File  |  1990-02-14  |  4.8 KB  |  188 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.14.15.23.28;  author tve;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Original X11R4 distribution
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/************************************************************************
  27. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  28. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  29.  
  30.                         All Rights Reserved
  31.  
  32. Permission to use, copy, modify, and distribute this software and its 
  33. documentation for any purpose and without fee is hereby granted, 
  34. provided that the above copyright notice appear in all copies and that
  35. both that copyright notice and this permission notice appear in 
  36. supporting documentation, and that the names of Digital or MIT not be
  37. used in advertising or publicity pertaining to distribution of the
  38. software without specific, written prior permission.  
  39.  
  40. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  41. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  42. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  43. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  44. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  45. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  46. SOFTWARE.
  47.  
  48. ************************************************************************/
  49.  
  50. /* $XConsortium: glyphcurs.c,v 5.1 89/07/03 13:27:00 rws Exp $ */
  51.  
  52. #include "X.h"
  53. #include "Xmd.h"
  54. #include "Xproto.h"
  55. #include "dixfontstr.h"
  56. #include "fontstruct.h"
  57. #include "scrnintstr.h"
  58. #include "gcstruct.h"
  59. #include "resource.h"
  60. #include "dix.h"
  61. #include "cursorstr.h"
  62. #include "misc.h"
  63. #include "opaque.h"
  64. #include "servermd.h"
  65.  
  66.  
  67. /*
  68.     get the bits out of the font in a portable way.  to avoid
  69. dealing with padding and such-like, we draw the glyph into
  70. a bitmap, then read the bits out with GetImage, which
  71. uses server-natural format.
  72.     since all screens return the same bitmap format, we'll just use
  73. the first one we find.
  74.     the character origin lines up with the hotspot in the
  75. cursor metrics.
  76. */
  77.  
  78. int
  79. ServerBitsFromGlyph(pfont, ch, cm, ppbits)
  80.     FontPtr    pfont;
  81.     unsigned short ch;
  82.     register CursorMetricPtr cm;
  83.     unsigned char **ppbits;
  84. {
  85.     register ScreenPtr pScreen;
  86.     register GCPtr pGC;
  87.     xRectangle rect;
  88.     PixmapPtr ppix;
  89.     long nby;
  90.     unsigned char *pbits;
  91.     XID gcval[3];
  92.     unsigned char char2b[2];
  93.  
  94.     /* turn glyph index into a protocol-format char2b */
  95.     char2b[0] = (unsigned char)(ch >> 8);
  96.     char2b[1] = (unsigned char)(ch & 0xff);
  97.  
  98.     pScreen = screenInfo.screens[0];
  99.     nby = PixmapBytePad(cm->width, 1) * (long)cm->height;
  100.     pbits = (unsigned char *)xalloc(nby);
  101.     if (!pbits)
  102.     return BadAlloc;
  103.     /* zeroing the (pad) bits seems to help some ddx cursor handling */
  104.     bzero((char *)pbits, nby);
  105.  
  106.     ppix = (PixmapPtr)(*pScreen->CreatePixmap)(pScreen, cm->width,
  107.                            cm->height, 1);
  108.     pGC = GetScratchGC(1, pScreen);
  109.     if (!ppix || !pGC)
  110.     {
  111.     if (ppix)
  112.         (*pScreen->DestroyPixmap)(ppix);
  113.     if (pGC)
  114.         FreeScratchGC(pGC);
  115.     xfree(pbits);
  116.     return BadAlloc;
  117.     }
  118.  
  119.     rect.x = 0;
  120.     rect.y = 0;
  121.     rect.width = cm->width;
  122.     rect.height = cm->height;
  123.  
  124.     /* fill the pixmap with 0 */
  125.     gcval[0] = GXcopy;
  126.     gcval[1] = 0;
  127.     gcval[2] = (XID)pfont;
  128.     DoChangeGC(pGC, GCFunction | GCForeground | GCFont, gcval, 1);
  129.     ValidateGC((DrawablePtr)ppix, pGC);
  130.     (*pGC->ops->PolyFillRect)(ppix, pGC, 1, &rect);
  131.  
  132.     /* draw the glyph */
  133.     gcval[0] = 1;
  134.     DoChangeGC(pGC, GCForeground, gcval, 0);
  135.     ValidateGC((DrawablePtr)ppix, pGC);
  136.     (*pGC->ops->PolyText16)(ppix, pGC, cm->xhot, cm->yhot, 1, char2b);
  137.     (*pScreen->GetImage)(ppix, 0, 0, cm->width, cm->height,
  138.              ZPixmap, 1, pbits);
  139.     *ppbits = pbits;
  140.     FreeScratchGC(pGC);
  141.     (*pScreen->DestroyPixmap)(ppix);
  142.     return Success;
  143. }
  144.  
  145.  
  146. Bool
  147. CursorMetricsFromGlyph( pfont, ch, cm)
  148.     register FontPtr     pfont;
  149.     unsigned        ch;
  150.     register CursorMetricPtr cm;
  151. {
  152.     register CharInfoPtr     pci;
  153.  
  154.     if (   ch < pfont->pFI->chFirst
  155.     || ch >= pfont->pFI->chFirst + n1dChars(pfont->pFI))
  156.     return FALSE;
  157.     pci = ADDRXTHISCHARINFO(pfont, ch);
  158.     cm->width = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
  159.     cm->height = pci->metrics.descent + pci->metrics.ascent;
  160.     if (pci->metrics.leftSideBearing > 0)
  161.     {
  162.     cm->width += pci->metrics.leftSideBearing;
  163.     cm->xhot = 0;
  164.     }
  165.     else
  166.     {
  167.     cm->xhot = -pci->metrics.leftSideBearing;
  168.     if (pci->metrics.rightSideBearing < 0)
  169.         cm->width -= pci->metrics.rightSideBearing;
  170.     }
  171.     if (pci->metrics.ascent < 0)
  172.     {
  173.     cm->height -= pci->metrics.ascent;
  174.     cm->yhot = 0;
  175.     }
  176.     else
  177.     {
  178.     cm->yhot = pci->metrics.ascent;
  179.     if (pci->metrics.descent < 0)
  180.         cm->height -= pci->metrics.descent;
  181.     }
  182.     return TRUE;
  183. }
  184.  
  185.  
  186.  
  187. @
  188.